#!/usr/bin/env python
# encoding=utf-8

import json
import sys

import requests

from config import BAIDU_MAP_ACCESS_KEY as ACCESS_KEY

reload(sys)
sys.setdefaultencoding('utf-8')

__author__ = 'xlzd'

API_URL = 'http://api.map.baidu.com/place/v2/search?ak=%s&output=json&query=' \
          '{address}&page_size=20&page_num=0&scope=2&region={city}' % ACCESS_KEY


def query_location(city, address):
    return requests.get(API_URL.format(city=city, address=address)).json()['results']


def main():
    data = query_location(u'重庆', u'居易国际广场')
    print json.dumps(data, ensure_ascii=False, indent=4, sort_keys=True)

if __name__ == '__main__':
    # from fuzzywuzzy import fuzz
    # python-Levenshtein
    # print fuzz.ratio(u'力华科谷', u'力华科谷2号门')
    main()
